﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<WebHoiChoMuaBan.Models.BannerAdList>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    ListBannerAd
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="ButtonFunction">
         <a href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
            title="" onclick="viewBannerAd()"><span class="ui-button-icon-primary ui-icon ui-icon-plus ">
            </span><span class="ui-button-text">Sửa</span> </a><a href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                title="" onclick="deleteBannerAd()"><span class="ui-button-icon-primary ui-icon ui-icon-minus ">
                </span><span class="ui-button-text">Xóa</span> </a><a href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                    title=""><span class="ui-button-icon-primary ui-icon ui-icon-cancel "></span><span
                        class="ui-button-text">Khóa TK</span> </a><a href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                            title=""><span class="ui-button-icon-primary ui-icon ui-icon-mail-closed "></span>
                            <span class="ui-button-text">Mở TK</span> </a><a href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                                title=""><span class="ui-button-icon-primary ui-icon ui-icon-mail-closed "></span>
                                <span class="ui-button-text">Mail All</span> </a><a href="#" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"
                                    title=""><span class="ui-button-icon-primary ui-icon ui-icon-mail-closed "></span>
                                    <span class="ui-button-text">Mail</span> </a>
    </div>
    <div class="Pagging">
        <form method="get" action="<%=Request.Path %>" name="frmPagingUp">
        <% 
            if (Model.TotalPages > 1)
            {
                if (Model.CurrentPage > 1)
                {
        %>
        <a href="?page=<%=Model.CurrentPage-1 %>">Trang trước</a>
        <%
}
        %>
        <select name="page" onchange="frmPagingUp.submit()">
            <%
                for (int i = 1; i <= Model.TotalPages; i++)
                {
                    if (i == Model.CurrentPage)
                    {
            %>
            <option value="<%=i %>" selected="selected">
                <%=i%></option>
            <%
}
                    else
                    {
            %>
            <option value="<%=i %>">
                <%=i%></option>
            <%
                }
                }
            %>
        </select>
        <%
            if (Model.CurrentPage < Model.TotalPages)
            {
        %>
        <a href="?page=<%=Model.CurrentPage+1 %>">Trang sau</a>
        <%
            }
            } //if (Model.TotalPages > 1)
        %>
        </form>
    </div>
    <script type="text/javascript">
        function clearAllRadios(obj) {
            var input = document.getElementsByTagName("input");
            for (var i = 0; i < input.length; i++) {
                if (input[i].checked) input[i].checked = false;
            }
            obj.checked = true;

        }

        function deleteBannerAd() {
            var input = document.getElementsByTagName("input");
            var spid = 0;
            for (var i = 0; i < input.length; i++) {
                if (input[i].checked == true) {
                    spid = input[i].value;
                    break;
                }
            }
            $.ajax({
                type: "POST",
                url: "/BannerAd/DeleteBannerAd",
                data: "cusId=" + spid,
                success: function (result) {
                    alert("xóa banner thành công !");
                    location.reload(true);

                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

        function viewBannerAd() {
            var input = document.getElementsByTagName("input");
            var spid = 0;
            for (var i = 0; i < input.length; i++) {
                if (input[i].checked == true) {
                    spid = input[i].value;
                    break;
                }
            }
            $.ajax({
                type: "POST",
                url: "/BannerAd/viewBannerAd",
                data: "bannerId=" + spid,
                success: function (result) {
                    window.location = "CreateBannerAd?bannerId=" + spid;
                },
                error: function (req, status, error) {
                    alert("Sorry! We could not receive your feedback at this time.");
                }
            });
        }

        function updateCustomerStatus(test) {
            $.ajax({
                type: "POST",
                url: "/Customer/ChangeStatusCustomer",
                data: "cusId=" + test,
                success: function (result) {
                    location.reload(true);
                },
                error: function (req, status, error) {

                }
            });
        }
    </script>
    <div class="Clear">
    </div>
    <form method="post" action="" id="frmNewMember">
    <input type="hidden" id="inputNumber" name="inputNumber" />
    <table border="0px" cellpadding="3px" cellspacing="0px" width="100%">
        <tr>
            <th width="10px">
                <input id="cbSelectAllMem" type="checkbox" />
            </th>
            <th>
                Banner
            </th>
            <th>
                Mô tả
            </th>
            <th>
                Ngày đăng
            </th>
            <th>
                Ngày kết thúc
            </th>
            <th>
                Lượt CLick
            </th>
            <th>
                Trạng thái
            </th>
        </tr>
        <%
            foreach (var mem in Model.Bannerads)
            { 
        %>
        <tr>
            <td>
                <input name="selectedMem" value="<%=mem.BannerId %>" onclick='clearAllRadios(this)'
                    type="checkbox" />
            </td>
            <td width="20px">
                <%
                    if (!mem.BannerImg.Contains("http://"))
                    {
                %>
                <img src="../../../Content/Images/Upload/<%=mem.BannerImg %>" alt="" width="50" height="50" />
                <%
                    }
                    else
                    {
                %>
                <img src="<%=mem.BannerImg %>" alt="" width="50" height="50" />
                <%} %>
            </td>
            <%-- <td>
                <div class="Header">
                    <%=mem.BannerImg %></div>
            </td>--%>
            <td>
                <center>
                    <div class="Description">
                        <%=mem.BannerText %></div>
                </center>
            </td>
            <td class="Header">
                <center>
                    <%=mem.BannerStartDate %>
                </center>
            </td>
            <td class="Header">
                <center>
                    <%=mem.BannerEndDate %>
                </center>
            </td>
            <td>
                <center>
                    1
                </center>
            </td>
            <td>
                <center>
                    <%
                        string icon, msg, actionUrl;
                        if (mem.BannerStatus.ToString().Equals(WebHoiChoMuaBan.Models.BannerAd.Status.Active.ToString()))
                        {
                            icon = "ui-icon-check";
                            msg = "Đang kích hoạt. Hãy nhấn nút để Khóa";
                            actionUrl = "ChangeStatusCustomer";
                        }
                        else
                        {
                            icon = "ui-icon-locked";
                            msg = "Đang bị khóa. Hãy nhấn nút để Kích hoạt";
                            actionUrl = "ChangeStatusCustomer";
                        }
                    %>
                    <a href="" id="statusClick" data-url="<%=mem.BannerId %>" onclick="updateCustomerStatus(<%=mem.BannerId %>)"
                        class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only"
                        title="<%=msg %>"><span class="ui-button-icon-primary ui-icon <%=icon %> "></span>
                        <span class="ui-button-text">Button with icon only</span> </a>
                </center>
            </td>
        </tr>
        <%
            }
        %>
        <%--        <tr>
                <td><input id="Checkbox2" type="checkbox" /></td>
                <td width="20px">
                    <img src="../../Content/Images/envelop.png" alt="" />
                </td>
                <td>
                    <div class="Header">Demo</div>
                    <div class="Description">Tên đăng nhập : Demo</div>
                    <div class="Description">Mail : Demo@Demo.com </div>
                </td>
                <td class="Header">000000000</td>
                <td class="Header">0000</td>
                <td class="Header">Trang profile</td>
                <td>
                    <div class="BtnGold BtnSmallButtom" >
                        <a href="#" class="_input">Vàng</a>
                    </div>
                </td>
                <td>
                    <a href="#"><img src="../../../Content/Images/delete.png" alt="" class="Icon-Delete"/></a>
                    <input id="Checkbox3" type="checkbox" disabled="disabled" checked="checked"/>
                    
                </td>
            </tr>--%>
    </table>
    </form>
    <div class="Pagging">
        <form method="get" action="<%=Request.Path %>" name="frmPagingUp">
        <% 
            if (Model.TotalPages > 1)
            {
                if (Model.CurrentPage > 1)
                {
        %>
        <a href="?page=<%=Model.CurrentPage-1 %>">Trang trước</a>
        <%
}
        %>
        <select name="page" onchange="frmPagingUp.submit()">
            <%
                for (int i = 1; i <= Model.TotalPages; i++)
                {
                    if (i == Model.CurrentPage)
                    {
            %>
            <option value="<%=i %>" selected="selected">
                <%=i%></option>
            <%
}
                    else
                    {
            %>
            <option value="<%=i %>">
                <%=i%></option>
            <%
                }
                }
            %>
        </select>
        <%
            if (Model.CurrentPage < Model.TotalPages)
            {
        %>
        <a href="?page=<%=Model.CurrentPage+1 %>">Trang sau</a>
        <%
            }
            } //if (Model.TotalPages > 1)
        %>
        </form>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
</asp:Content>
